<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>首页添加</title>
<link href="<%=basePath%>skin/css/validform/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath%>skin/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/validform/Validform_v5.3.2_min.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/common.js"></script>
<script language="javascript">
	$().ready(function(){
		//验证
		var validform = $("#form1").Validform({
			btnSubmit:"#save",
			tiptype:3,
			beforeSubmit:function(curform){
				var type = $("#type").val();
				if (type == null || type == "") {
					alert("请选择类型!");
					return false;
				}
				if (type == 2 || type == 3) {
					var price = $("#price").val();
					var promotionPrice = $("#promotionPrice").val();
					var decimalReg=/^\d{0,8}\.{0,1}(\d{1,2})?$/;
					if(!decimalReg.test(price)){
						alert("请填写数字或小数!");
						$("#price").focus();
						return false;
					}
					if(!decimalReg.test(promotionPrice)){
						alert("请填写数字或小数!");
						$("#promotionPrice").focus();
						return false;
					}
				}
				
				var url = $("#url").val();
				if (url == null || url == "") {
					alert("请输入网址!");
					return false;
				}				
			}
		});
		validform.addRule([
			{
			    ele:"#orders",
			    datatype:"n",
			    nullmsg:"请输入排序！"
			},
			{
			    ele:"#title",
			    datatype:"*",
			    nullmsg:"请输入标题！"
			},
			{
			    ele:"#file",
			    datatype:"*",
			    nullmsg:"请选择图片！"
			}
		]);
		
		$("#type").change(function(){
			var value = $(this).val();
			if (value == 2 || value == 3) {
				$("#priceTr").show();
				$("#promotionPriceTr").show();
			} else {
				$("#priceTr").hide();
				$("#promotionPriceTr").hide();
			}
		});
	 });
</script>
</head>

<body>
	<form id="form1" name="form1" method="post" action="<%=basePath%>admin/indexImage/save.shtml" enctype="multipart/form-data">
		<table width="98%" class="input tabContent">
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">类型：</td>
				<td class="tdLeft">
					<select name="type" id="type">
						<option value=""></option>
						<option value="0">轮播图片</option>
						<option value="1">产品分类</option>
						<option value="2">大家都喜欢</option>
						<option value="3">新品上架</option>
						<option value="4">热销排行</option>
					</select>
				</td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">排序：</td>
				<td class="tdLeft"><input id="orders" name="orders"
					size="30" class="input" /></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">标题：</td>
				<td class="tdLeft"><input id="title" name="title"
					size="30" class="input" /></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">网址：</td>
				<td class="tdLeft"><input id="url" name="url"
					size="30" class="input" /></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22" id="priceTr" style="display:none">
				<td class="tdRight">原价：</td>
				<td class="tdLeft"><input id="price" name="price"
					size="30" class="input" /></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22" id="promotionPriceTr" style="display:none">
				<td class="tdRight">促销价：</td>
				<td class="tdLeft"><input id="promotionPrice" name="promotionPrice"
					size="30" class="input" /></td>
			</tr>
			<tr bgcolor="#FAFAF1" height="22">
				<td class="tdRight">图片：</td>
				<td class="tdLeft">
					<input type="file" name="file" id="file"/>
				</td>
			</tr>
		</table>
		<table width="98%">
			<tr bgcolor="#EEF4EA">
				<td height="36" colspan="10">
					<input type="button" value="确定" class="button" id="save" />
					<input type="button" value="返回" class="button" onclick="location.href='<%=basePath%>admin/indexImage/list.shtml'" />
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
